<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	response.setContentType("text/html;charset=utf-8");
	response.setCharacterEncoding("utf-8");
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>业务编辑</title>
<link href="<%=path%>/favicon.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/public.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/style_list.css" />


<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0"
	rel="stylesheet">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
<link href="<%=path%>/css/marketing/s_style.css" rel="stylesheet">

</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-1"></div>
				<div class="col-md-10 white-bg">
					<div class="row">
						<div style="height: 40px">
							<center>
								<h4 style="padding-top: 10px;">编辑业务介绍</h4>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 5px;"></div>
						<div style="padding-left: 90px; width: 90%">
							<div id="editor"></div>
							<h3>&nbsp;</h3>
							<form method="get"
								class="form-horizontal m-t commithtml text-center"></form>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 10px"></div>
						<div style="height: 25px">
							<center>
								<b>辑显示卡片</b>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 180px;">
							<div class="row"
								style="padding-left: 90px; padding-top: 15px; float: left;">
								<form id='pic_' action="post"
									class="form-vertical m-t text-left col-md-6"
									enctype='multipart/form-data'>
									<div class="x_img_sc">
										<img id="img3" src="<%=path%>/images/marketing/img_p.png"
											style="width: 120px; height: 120px;">
									</div>
									<input type="file" accept="image/gif,image/jpeg,image/x-png"
										id="pic" onchange="fileloadon('pic')" name="filepath"
										style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99; width: 120px; height: 120px;">
								</form>
							</div>
							<div
								style="padding-left: 270px; padding-top: 25px; padding-right: 90px;">
								<input maxlength="20" id="title" class="form-control" placeholder="编辑标题" />
								<div style="padding-top: 10px;"></div>
								<div>
									<textarea style="width: 100%;" id="content" maxlength="68"
										class="panel panel-default panel-body col-sm-6"
										placeholder="编辑简介"></textarea>
								</div>
							</div>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 10px"></div>
						<div style="height: 25px">
							<center>
								<b>尾页二维码</b>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 180px;">
							<table>
								<tr>
									<td style="width: 222px;"></td>
									<td></td>
									<td></td>
									<td><div>
											<form id='_weixin_qrcode' action="post"
												class="form-vertical m-t text-left col-md-6"
												enctype='multipart/form-data'>
												<div class="row">
													<div class="x_img_sc">
														<img id="img4" src="<%=path%>/images/marketing/img_p.png"
															style="width: 100px; height: 100px;">
													</div>
													<input type="file"
														accept="image/gif,image/jpeg,image/x-png" id="x_inputfile"
														onchange="fileloadon('weixin')" name="filepath"
														style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99;">
												</div>

											</form>
										</div></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td><div>
											<form id='_weibo_qrcode' enctype='multipart/form-data'
												action="post" class="form-vertical m-t text-left col-md-6">
												<div class="row">
													<div class="x_img_sc">
														<img id="img5" src="<%=path%>/images/marketing/img_p.png"
															style="width: 100px; height: 100px;" />
													</div>
													<input type="file"
														accept="image/gif,image/jpeg,image/x-png" id="b_inputfile"
														onchange="fileloadon('weibo')" name="filepath"
														style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99; height: 100px; width: 100" />
												</div>

											</form>
										</div></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td></td>
									<td><div>
											&nbsp; <label class="checkbox-inline i-checks"
												style="margin-left: -9px; margin-top: 5px"><input
												id="input_weixin" type="checkbox" name="code" value="weixin2">微信二维码</label>
										</div></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td><div>
											&nbsp; <label id="bo" class="checkbox-inline i-checks"
												style="margin-left: -9px; margin-top: 5px"><input
												id="input_weibo" type="checkbox" value="weibo2">微博二维码
											</label>
										</div></td>
									<td></td>
									<td></td>
									<td></td>
								</tr>
							</table>
						</div>
						<div class="gray-bg" style="padding-bottom: 15px;"></div>
						<div style="height: 70px;">
							<center>
								<button class="btn btn-primary" onclick="back_()"
									style="margin-top: 18px; margin-right: 5px;">返回</button>
								<button class="btn btn-primary" onclick="preview_()"
									style="margin-top: 18px; margin-right: 5px;">预览</button>
								<button class="btn btn-primary" onclick="save()"
									style="margin-top: 18px;">保存</button>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 80px;"></div>
					</div>
				</div>
				<div class="col-md-1"></div>
			</div>

		</div>
	</div>


	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

	<script type="text/javascript"
		src="<%=path%>/js/marketing/ajaxfileupload.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<script type="text/javascript"
		src="<%=path%>/js/marketing/lengthlimit.js"></script>


	<script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
	<%--<script type="text/javascript"--%>
		<%--src="<%=path%>/js/marketing/ckeditor/ckeditor.js"></script>--%>

	<script type="text/javascript"
			src="<%=path%>/js/marketing/ckeditor/ckeditor.js"></script>
	<script type="text/javascript"
			src="<%=path%>/js/marketing/ckeditor/sample.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript">
	//单选按钮二维码
    $('#input_weixin').on('ifChecked', function(){
		$("#input_weibo").iCheck("uncheck");
		//$("#x_inputfile").trigger("click");
     });
     $('#input_weibo').on('ifChecked', function(){
    	$("#input_weixin").iCheck("uncheck");
		//$("#b_inputfile").trigger("click");
     });
    /*  $('#x_inputfile').click(function(){
		$("#input_weixin").iCheck("check");
     });
     $('#b_inputfile').click( function(){
    	$("#input_weibo").iCheck("check");
     }); */
	 
     //返回
     function back_(){
    	 location.href="<%=path%>/view/ui/toDistinctionList";
     }
		
		/* ckeditor相关   --start */
		/* initSample(); */
		var editor = CKEDITOR.replace('editor', {
			"filebrowserUploadUrl" : "${pageContext.request.contextPath}/api/uploadfile/uploadCKImg",
			enterMode :CKEDITOR.ENTER_BR //换行直接加br
		});
		
		
		$('img').error(function(){
		    $(this).attr('src', '<%=path%>/images/marketing/img_load_error.png');
		});
		
		var choseQrWeixinFlag=false;
		var choseQrWeiboFlag=false;
		var commit_info = "";
			
	</script>

	<script type="text/javascript">
	$.fn.dataTable.ext.errMode = 'none';
	 	var access_token=$.cookie('access_token');
	    var cid=$.cookie('cid');
	    var uid=$.cookie('uid');
	    //标题
	    var title;
	    var id="";
	    //二维码
	    var weibo_qrcode;
	    var weixin_qrcode;
	    //卡片
	    var title_pic;

	    var save_tag=false;
	    
	    

	    var next_flag;
	    //简介
	    var content;
	    //1预览0保存
	    var status="0";
	    var store_names=new Array();
	    var store_ids=new Array();
	    var type;
		var flag=false;
	    //初始化
	    $(function(){
	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
	    	id=getQueryString("id");
	    	type="activity";
	    	
	    	console.log("type---->"+type);
			  window.addEventListener("popstate", function(e) {
				  if(type=="model"&&StringEmpty(model_id)){
			    		cancelModelEdit();
			      }else{
			    		history.go(-1);
			      }
			  }, false);
	    	
	    	
	    	if((type=="model"||type=="model_copy")&&StringEmpty(model_id)){
	    		$(document).attr("title","模板编辑");
	    		$('#set_button1').show();
	    		$('#set_button2').show();
	    		
	    		$('#title_name').html("模板名称");
	    		
	    		$("#x_button_bm").text("预览");
	    		$("#x_button_y").text("保存");
	    		$(".k_radio").show();
	    		
	    	}else{
	    		
	    		$("#x_button_bm").text("预览");
	    		$(".k_radio").show();
	    		$("#x_button_y").text("保存");
	    	}
	    	getModelInfo();
	    });
	    
	    
	  	
		function getModelInfo() {
			var url = "<%=path%>/distinction/ajaxDistinctionData";
			$.post(url, {"id":id},function(data) {
				if (data.id!=0) {
					//
					intModelHtml(data);
				} else {
					errorDialog("获取数据失败","");
				}
			});
		}
		
		
		//设置html
		function intModelHtml(data) {
			setTimeout(function () {
				//设置自定义文本内容信息
				var cktext_info = data.description;
				//CKEDITOR.instances.editor.setData(cktext_info);
				editor.setData(cktext_info);
				console.log("activity:model:3:");
			}, 1000);
			
			//设置二维码
			if(StringEmpty(data.weiboQrcode)){
				weibo_qrcode=data.weiboQrcode;
				document.getElementById('img5').src = data.weiboQrcode;
				$('#input_weibo').iCheck("check"); 
			}
			if(StringEmpty(data.weixinQrcode)){
				weixin_qrcode=data.weixinQrcode;
				document.getElementById('img4').src = data.weixinQrcode;	
				$('#input_weixin').iCheck("check"); 
			}
            content=data.content;
			if(StringEmpty(content))
				$('#content').val(content);
			$('#title').val(data.title);
			
			if(StringEmpty(data.pic)){
				title_pic=data.pic;
				$("#pic").attr("src",title_pic);
				document.getElementById('img3').src = data.pic;
				
			}
			id=data.id;
		}
	
		//预览
	  	function preview_(){
	  		title=document.getElementById("title").value;
			text_info=CKEDITOR.instances.editor.getData();
			content=$('#content').val();
			if(title!=""){
				if(text_info!=""){
					if(content!=""){
						if(title_pic!=undefined){
							if($('#input_weibo').is(':checked')){
								weixin_qrcode="";
							}else if($('#input_weixin').is(':checked')){
								weixbo_qrcode="";
							}else{
								weibo_qrcode="";
								weixin_qrcode="";
							}
							status="1";
							updateDistinction();
						}else{
								errorDialog("请上传卡片！","");
						}
					}else{
						errorDialog("业务简介不能为空！","");
					}
				}else{
					errorDialog("业务介绍不能为空！","");
				}
			}else{
				errorDialog("标题不能为空！","");
			}
				
	  	}
		
		
		
		//保存
		function save() {
			//获取输入的活动标题
			title=document.getElementById("title").value;
			text_info=CKEDITOR.instances.editor.getData();
			content=$('#content').val();
			if(title!=""){
				if(text_info!=""){
					if(content!=""){
						if(title_pic!=undefined){
							if($('#input_weibo').is(':checked')){
								weixin_qrcode="";
							}else if($('#input_weixin').is(':checked')){
								weixbo_qrcode="";
							}else{
								weibo_qrcode="";
								weixin_qrcode="";
							}
							updateDistinction();
						 }else{
								errorDialog("请上传卡片！","");
						} 
					}else{
						errorDialog("业务简介不能为空！","");
					}
				}else{
					errorDialog("业务介绍不能为空！","");
				}
			}else{
				errorDialog("标题不能为空！","");
			}
		}
		
		// 更新业务
		function updateDistinction(){
			var url = "<%=path%>/distinction/ajaxDistinctionUpdateSelective";
			$.post(url, {
				"access_token" :access_token,
				"cid" : cid,
				"uid" : uid,
				"title" : title,
				"weixinQrcode" : weixin_qrcode,
				"weiboQrcode" : weibo_qrcode,
				"pic" : title_pic,
				"headPic" : title_pic,
				"description" : text_info,
				"content" : content,
				"id":id,
				"status":status
			}, function(data) {
				
				if (data == 1 && status=="0") {
					location.href="<%=path%>/view/ui/toDistinctionList";
				} else if(data==1 && status=="1"){
					location.href="<%=path%>/distinction/toPreview?id="+id;
				} else {
					errorDialog(data.message,"");
				}
			});
		}
		var flag=false;
        function fileloadon(upload_type) {
        	var imgUrl = "<%=path%>/images/marketing/img_p.png";
        	//上传微信二维码
            $("#_weixin_qrcode").submit(function () {
            	$("#input_weixin").iCheck("check");
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#_weixin_qrcode").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (data1) {
                        if (data1.realSavePath == undefined){
                            return false;
                        }
                    	weibo_qrcode=null;
                    	weixin_qrcode=data1.realSavePath;
                    	$("#img4").attr('src',weixin_qrcode);
                    	$("#img5").attr('src',imgUrl);
                    	$("#erweima_weixin2").attr('src',weixin_qrcode); 
                    	choseQrWeixinFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");    
                    }
                });
                return false;
            });
            
            //上传微博二维码
            $("#_weibo_qrcode").submit(function () {
            	$("#input_weibo").iCheck("check");
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#_weibo_qrcode").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (data1) {
                        if (data1.realSavePath == undefined){
                            return false;
                        }
                    	weixin_qrcode= null;
                    	weibo_qrcode=data1.realSavePath;
                    	$("#img5").attr('src',weibo_qrcode); 
                    	$("#img4").attr('src',imgUrl);
                    	$("#erweima_weibo2").attr('src',weibo_qrcode); 
                    	choseQrWeiboFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");    
                    }
                });
                return false;
            });
            //上传卡片
            $("#pic_").submit(function () {
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#pic_").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (e) {
                        if (e.realSavePath == undefined){
                            return false;
                        }
                    	title_pic=e.realSavePath;
                    	$("#img3").attr('src' , e.realSavePath);  
                    	choseQrWeiboFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");    
                    }
                });
                return false;
            });
            switch (upload_type) {
            
			case "weixin":
				flag=false;
				$("#_weixin_qrcode").submit();
				break;
			case "weibo":
				flag=false;
				$("#_weibo_qrcode").submit();
				break;
			case "pic":
				flag=false;
				$("#pic_").submit();
				break;

			default:
				break;
			}
        }
	</script>
</body>
</html>
